package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"video_07_21/api/request"
	"video_07_21/internal/dao"
	"video_07_21/internal/model"
	"video_07_21/pkg"
)

func RegisterUser(c *gin.Context) {

	var req request.RegisterUserForm
	var user model.User

	if err := c.ShouldBind(&req); err != nil {
		return
	}

	if req.Mobile == "" || req.Password == "" {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	user = model.User{
		Mobile:   req.Mobile,
		Password: pkg.Md5(req.Password),
	}

	err := dao.AddFile(&user)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "注册失败",
			"data": nil,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "注册成功",
		"data": nil,
	})

}

func LoginUser(c *gin.Context) {

}
